package cn.flant.util;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.Arrays;

public class SystemEnv {
	public static String getAwtToolkit() {
		return System.getProperty("awt.toolkit");
	}

	public static String getAwtGraphicsenv() {
		return System.getProperty("java.awt.graphicsenv");
	}

	public static String getAwtPrinterJob() {
		return System.getProperty("java.awt.printerjob");
	}

	public static String getFileEncoding() {
		return System.getProperty("file.encoding");
	}

	public static String getFileEncodingPkg() {
		return System.getProperty("file.encoding.pkg");
	}

	public static String getFileSeparator() {
		return System.getProperty("file.separator");
	}

	public static String getClassPath() {
		return System.getProperty("java.class.path");
	}

	public static String getClassVersion() {
		return System.getProperty("java.class.version");
	}

	public static String getEndorsedDirs() {
		return System.getProperty("java.endorsed.dirs");
	}

	public static String getExtDirs() {
		return System.getProperty("java.ext.dirs");
	}

	public static String getJavaHome() {
		return System.getProperty("java.home");
	}

	public static String getTempDir() {
		return System.getProperty("java.io.tmpdir");
	}

	public static String getLibraryPath() {
		return System.getProperty("java.library.path");
	}

	public static String getJavaRuntimeName() {
		return System.getProperty("java.runtime.name");
	}

	public static String getJavaRuntimeVersion() {
		return System.getProperty("java.runtime.version");
	}

	public static String getSpecificationName() {
		return System.getProperty("java.specification.name");
	}

	public static String getSpecificationVendor() {
		return System.getProperty("java.specification.vendor");
	}

	public static String getSpecificationVersion() {
		return System.getProperty("java.specification.version");
	}

	public static String getJavaVendor() {
		return System.getProperty("java.vendor");
	}

	public static String getJavaVendorUrl() {
		return System.getProperty("java.vendor.url");
	}

	public static String getJavaVendorBugUrl() {
		return System.getProperty("java.vendor.url.bug");
	}

	public static String getJavaVersion() {
		return System.getProperty("java.version");
	}

	public static String getJVMInfo() {
		return System.getProperty("java.vm.info");
	}

	public static String getJVMName() {
		return System.getProperty("java.vm.name");
	}

	public static String getJVMVendor() {
		return System.getProperty("java.vm.vendor");
	}

	public static String getJVMVersion() {
		return System.getProperty("java.vm.version");
	}

	public static String getJVMSpecificationName() {
		return System.getProperty("java.vm.specification.name");
	}

	public static String getJVMSpecificationVendor() {
		return System.getProperty("java.vm.specification.vendor");
	}

	public static String getJVMSpecificationVersion() {
		return System.getProperty("java.vm.specification.version");
	}

	public static String getLineSeparator() {
		return System.getProperty("line.separator");
	}

	public static String getOSArch() {
		return System.getProperty("os.arch");
	}

	public static String getOSName() {
		return System.getProperty("os.name");
	}

	public static String getOSVersion() {
		return System.getProperty("os.version");
	}

	public static String getOSPatchLevel() {
		return System.getProperty("sun.os.patch.level");
	}

	public static String getPathSeparator() {
		return System.getProperty("path.separator");
	}

	public static String getArchDataModel() {
		return System.getProperty("sun.arch.data.model");
	}

	public static String getBootClassPath() {
		return System.getProperty("sun.boot.class.path");
	}

	public static String getBootLibraryPath() {
		return System.getProperty("sun.boot.library.path");
	}

	public static String getUserCountry() {
		return System.getProperty("user.country");
	}

	public static String getUserDir() {
		return System.getProperty("user.dir");
	}

	public static String getUserHome() {
		return System.getProperty("user.home");
	}

	public static String getUserLanguage() {
		return System.getProperty("user.language");
	}

	public static String getUserName() {
		return System.getProperty("user.name");
	}

	public static String getUserTimeZone() {
		return System.getProperty("user.timezone");
	}

	public static String getUserVariant() {
		return System.getProperty("user.variant");
	}

	public static String getEnviroment(String name) {
		return System.getenv(name);
	}

	public static int getPid() {
		try {
			RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
			String name = runtime.getName(); // format: "pid@hostname"
			return Integer.parseInt(name.substring(0, name.indexOf('@')));
		} catch (Exception e) {
			return -1;
		}
	}

	public static void main(String[] args) {
		String[] keys = System.getenv().keySet().toArray(new String[0]);
		Arrays.sort(keys);
		for (String key : keys) {
			System.out.println(key + "=" + System.getenv(key.toLowerCase()));
		}

		keys = System.getProperties().keySet().toArray(new
				String[0]);
		Arrays.sort(keys);
		for (String key : keys) {
			System.out.println(key + "=" + System.getProperty(key));
		}
	}
}
